<?php

namespace app\index\controller\goods\record;

use app\common\controller\Frontend;
use app\common\model\goods\record\Token as TokenModel;

/**
 * 充值
 */
class Token extends Frontend
{
    protected $layout = 'default';
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];
	protected $model;

	public function _initialize(){
        parent::_initialize();

		$this->model = new TokenModel();
	}

    /**
     * 商品列表
     * @return string
     */
    public function index($type = '')
    {
		$where = ['user_id' => $this->auth->id];
		switch ($type) {
			case 'income':
				$where['token'] = ['>=', 0];
				break;
			case 'expenses':
				$where['token'] = ['<', 0];
				break;
		}
		$list = $this->model->where($where)
            ->order('id desc')
            ->paginate(10);

        $this->view->assign('title', __('积分记录'));
        $this->view->assign('list', $list);

        return $this->view->fetch();
    }
}
